package com.aiti.lulian.service.impl;

import com.aiti.base.core.base.service.iml.BaseSerivceImpl;
import com.aiti.lulian.dto.xlb.XlbEnterpriseDto;
import com.aiti.lulian.entity.xlb.XlbEnterprise;
import com.aiti.lulian.mapper.xlb.XlbEnterpriseMapper;
import com.aiti.lulian.service.IXlbEnterpriseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class XlbEnterpriseServiceImpl extends BaseSerivceImpl<XlbEnterpriseMapper, XlbEnterprise> implements IXlbEnterpriseService {

    @Autowired
    private XlbEnterpriseMapper xlbEnterpriseMapper;

    @Override
    public void saveOrUpdate(XlbEnterpriseDto dto) {
        XlbEnterprise xlbEnterprise = new XlbEnterprise();
        BeanUtils.copyProperties(dto, xlbEnterprise);
        XlbEnterprise xlbEnterpriseDB = xlbEnterpriseMapper.selectById(dto.getBaseId());
        if (xlbEnterpriseDB == null) {
            xlbEnterprise.setBaseCreateTime(new Date());
            xlbEnterprise.setBaseUpdateTime(new Date());
            this.save(xlbEnterprise);
        } else {
            xlbEnterprise.setBaseUpdateTime(new Date());
            this.updateById(xlbEnterprise);
        }
    }
}
